'use strict'
const fs = require('fs')
const path = require('path')
const cwd = process.cwd();

module.exports =  async (ctx, next) => {
    if (ctx.url === '/favicon.ico') {
        const iconPath = path.join(cwd, './favicon.ico');
        ctx.set('Content-Type', 'image/x-icon');
        ctx.body = await new Promise(resolve => resolve(fs.createReadStream(iconPath)));
    } else {
        await next()
    }
}
